package chapter1

import (
	"fmt"
	"time"
)

func consumer(data chan int,done chan bool){
	for x:=range data{
		fmt.Println("recv:",x)
	}
	done<-true
}

func producer(data chan int){
	for i:=0;i<4;i++{
		fmt.Println("进去一个",i)
		data<-i
		time.Sleep(time.Second)
	}

	close(data)
}

func Test4()  {
	data:=make(chan int)
	done:=make(chan bool)

	go consumer(data,done)
	go producer(data)

	<-done

}
